<template>
  <div>
    <el-card>
      <tag-content-header search refresh setting @toolFun="toolFun" :settingData="columns">
        <template #title>
          <span>标签上线平台列表</span>
        </template>
        <template #toolsPre>
          <el-tooltip effect="dark" content="导出上线平台" placement="top" slot="reference">
            <el-button type="primary" plain circle @click="handleDownload">
              <icon-svg name="iconDownload"></icon-svg>
            </el-button>
          </el-tooltip>
          <el-tooltip effect="dark" content="批量导入上线平台" placement="top">
            <el-button type="primary" plain circle @click="bathImport">
              <icon-svg name="iconImport"></icon-svg>
            </el-button>
          </el-tooltip>
        </template>
      </tag-content-header>
      <tag-table
        ref="table"
        @refresh="getList"
        :data="dataList"
        :loading="loading"
        :columns="columns"
        :params="params"
        :total="totalSize"
      >
      </tag-table>
    </el-card>
    <platform-import-drawer ref="platformImportDrawer" @refresh="getList"></platform-import-drawer>
    <platform-download-drawer ref="platformDownloadDrawer"></platform-download-drawer>
  </div>
</template>

<script>
import platformDownloadDrawer from './platform-download-drawer'
import platformImportDrawer from './platform-import-drawer'
export default {
  components: {
    platformDownloadDrawer,
    platformImportDrawer
  },
  data() {
    return {
      dataList: [],
      loading: false,
      columns: [
        {
          show: true,
          label: '标签名称',
          prop: 'tagNm',
          search: true,
          searchKey: ''
        },
        {
          show: true,
          label: '上线平台名称',
          prop: 'appPlfmNm',
          search: true,
          searchKey: '',
          align: 'center'
        }
      ],
      params: {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      },
      totalSize: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.$ajax({
        url: this.$ajax.setUrl('auth/admin/tagRolloutPlfmList'),
        method: 'get',
        params: this.$ajax.setParams(this.params)
      }).then(({ data }) => {
        if (data && data.code === '0') {
          if (data.data.currentPageNum === this.params.currentPageNum) {
            this.dataList = data.data.records
            this.totalSize = data.data.totalSize
          }
        } else {
          this.$message.error('获取上线平台列表失败！')
        }
        this.loading = false
      })
    },
    toolFun(operation) {
      switch (operation) {
        case 'search':
          // 搜索动作
          this.$refs['table'].searchToggle()
          break
        case 'refresh':
          // 刷新动作
          this.getList()
          break
      }
    },
    handleDownload() {
      this.$refs.platformDownloadDrawer.showDrawer()
    },
    bathImport() {
      this.$refs.platformImportDrawer.showDrawer()
    }
  }
}
</script>

<style lang="scss"></style>
